import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm'

interface UserProps {
    name?: string
    password?: string
    phone?: string
    email?: string
    wxOpenid?: string
    wxUnionid?: string
    token?: string
    state?: number
    [key: string]: any
}

@Entity()
export class User {
    @PrimaryGeneratedColumn()
        id?: number

    @Column({ nullable: true })
        name?: string

    @Column({ nullable: true })
        password?: string

    @Column({ nullable: true })
        phone?: string

    @Column({ nullable: true })
        email?: string

    @Column({ nullable: true })
        wxOpenId?: string

    @Column({ nullable: true })
        wxUnionId?: string

    @Column({ default: 1 })
        state?: number

    @Column({ nullable: true })
        token?: string

    @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
        createTime?: number

    constructor(props: UserProps | undefined) {
        if (!props) return
        this.name = props.name
        this.password = props.password
        this.phone = props.phone
        this.email = props.email
        this.wxOpenId = props.wxOpenId
        this.wxUnionId = props.wxUnionId
        this.token = props.token
        this.state = props.state
    }
}